<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class File_upload {//这个类是为了对session存入数据库做操作

    var $CI;
    var $session_id;
    var $session_array = array(); //是session实际的值，序列化后存入数组
    var $config;
    var $img_config;

    public function __construct() {
        $this->CI = & get_instance();
        $this->session_id = Session_id(); //开启sessionstart时候可以获取session_id
        $this->CI->load->database();

        $config['allowed_types'] = 'gif|jpg|png|GIF|JPG|PNG';
        $config['max_size'] = '10240';
        $config['max_width'] = '5000';
        $config['max_height'] = '5000';
        $config['encrypt_name'] = TRUE;
        $config['remove_spaces'] = TRUE;
        $img_config['image_library'] = 'GD2';
        $img_config['maintain_ratio'] = TRUE;
		$img_config['master_dim'] = 'auto';
        $img_config['width'] = 350;
        $img_config['height'] = 235;
		$img_config['x_axis'] = 0;
		$img_config['y_axis'] = 0;
        $this->config = $config;
        $this->img_config = $img_config;
    }

    public function upLoadfile($config_array, $text_filed) {//处理图片上传
        //参数配置数组，文本域名称
        $config = $this->config;
        $config['upload_path'] = $config_array['upload_path'];
        $this->CI->load->library('upload', $config);
        if (!$this->CI->upload->do_upload($text_filed)) {//上传不成功
            $error = array('error' => $this->CI->upload->display_errors());
        } else {//上传成功
            return $data = $this->CI->upload->data();
        }
        // print_r($config);
    }

    public function process_img($img_config_array) {//处理图片上传后缩略图
        //参数图片处理配置参数
      
        $img_config = $this->img_config; //图片处理配置文件
        $img_config['source_image'] = $img_config_array['source_image'];//原文件
        $img_config['new_image'] = $img_config_array['new_image'];//新地址
         // print_r($img_config);
        $this->CI->load->library('image_lib');
         $this->CI->image_lib->initialize($img_config);
        $this->CI->image_lib->resize();
		//$this->CI->image_lib->crop();
      //  print_r($img_config);
    }
    
    

}

/* End of file Someclass.php */